package com.nicy.angel.service.impl;


import com.nicy.angel.service.UserService;
import com.nicy.paradise.entity.User;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    /**
     * 删除用户（根据id）
     * @param id
     * @return
     */
    @Override
    public boolean deleteUser(String id) throws Exception {
        //HttpResponse<String> response = Unirest.delete("http://localhost:8086/user/delete/{id}")
                //.routeParam("id",id)
                //.asString();

        String result;

        //try {
            HttpResponse<String> response = Unirest.delete("http://localhost:8086/user/delete/{id}")
                    .routeParam("id", id)
                    .asString();

             response.ifFailure(response1 -> {
                log.error("接口出现异常");
            });

        System.out.println(response.isSuccess());

        //try{
            if(!response.isSuccess()){
                throw new Exception("天堂服务请求异常");
            }

        //} catch (Exception e) {
            //e.printStackTrace();
        //}

        result = response.getBody();

        System.out.println(response.getStatus());

        System.out.println(result);
        //}catch (Exception e){
            //log.error("接口调用出现异常");
        //}

        return true;
    }

    public HttpResponse<String> returnResult(HttpResponse<String> response){
        String body = response.getBody().toString();
        System.out.println(response.getBody());
        System.out.println(response.getStatus());
        return response;
    }
}
